<?php

include '../../../common.inc.php';
//exit();
var_dump($id);
$db->query('set names utf8');
$arr = $db->getAll("select * from wanche where id>$id and handle=0 limit 100 ");
if (!$arr) exit('over');
foreach($arr as $k => $v) {
	$text = getHandledText($v['answer']);
	if ($text) {
		$sql = "update wanche set handle=1 , answer = '{$text}' where id={$v['id']}";
	} else {
		$sql = "delete from wanche where id={$v['id']}";
	}
	$db->query($sql);
	$id = $v['id'];
}
// echo $id;
//var_dump( '<meta http-equiv="refresh" content="1; url=i.php?id='.$id.'" />');exit();
echo  '<meta http-equiv="refresh" content="1; url=i.php?id='.$id.'" />';

function getHandledText($text){
	if (preg_match('/^(.+)您好.*/', $text, $match)){
		$text = str_replace($match[1], '', $text);
	}
	if (preg_match('/(http:.*)$/', $text, $match2)) {
		$text = str_replace($match2[1], '', $text);
	}
	if (preg_match('/(电话.*)$/', $text, $match3)) {
		$text = str_replace($match3[1], '', $text);
	}
	if (preg_match('/(热线.*)$/', $text, $match4)) {
		$text = str_replace($match4[1], '', $text);
	}
	if (preg_match('/(万车|企业|预定|报价|优惠|目前|来店检查|现车|010|北京|销售)/', $text, $match5)) {
		$text = '';
	}
	return $text;
}
?>
